using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Checkpoint : MonoBehaviour
{

    private Transform renewPoint;
    private bool playerInrange;
    [SerializeField] private GameObject interactUI;
    void Start()
    {
        interactUI.SetActive(false);
        renewPoint = transform;
    }

    // Update is called once per frame
    void Update()
    {
        if(playerInrange&&Input.GetKeyDown(KeyCode.E))
        {
            ActiveCheckPoint();
            Debug.Log("SUCCESSED SAVE");
        }
    }
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            playerInrange = true;
        }
        interactUI.SetActive(true);
        
    }
    void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            playerInrange = false;
        }
         interactUI.SetActive(false);
    }
    void ActiveCheckPoint()
    {
        CheckpointManager.Instance.SetCheckPoint(renewPoint.position);
    }
}
